//
// FixedPointMethodTests.cpp
// Fixed Point Method Unit Tests.
//
// Author: Gabriel H. Barbuto (gbarbuto@dc.uba.ar)
//
#include <cmath>
#include <functional>

#include <boost/test/unit_test.hpp>

#include "FixedPointMethod.h"

BOOST_AUTO_TEST_SUITE(FixedPointMethodTests)

BOOST_AUTO_TEST_CASE(XSquaredFunction)
{
	double const EPSILON(0.0001);

	double const x0(2.0 / 3.0);
	FixedPointMethod method([](double const &x) { return x * x; });

	double const x(method(x0));

	BOOST_REQUIRE_SMALL(x, EPSILON);
}

BOOST_AUTO_TEST_CASE(ComplexFunction)
{
	double const EPSILON(0.0001);

	double const x0(2.0);
	FixedPointMethod method([](double const &x) { return std::pow((x + 10), 0.25); });

	double const x(method(x0));

	BOOST_REQUIRE_CLOSE(1.85558452, x, EPSILON);
}

BOOST_AUTO_TEST_CASE(AnotherComplexFunction)
{
	double const EPSILON(0.0001);

	double const x0(2.0 / 3.0);
	FixedPointMethod method([](double const &x) { return (x * x * x + 2) / 7.0; });

	double const x(method(x0));

	BOOST_REQUIRE_CLOSE(0.28916854, x, EPSILON);
}

BOOST_AUTO_TEST_SUITE_END()

